package ling.common.domain;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.var;

import java.util.List;

/**
 * 兼容ruoyi分页对象TableDataInfo
 * @param <T>
 */
public class ResultRows<T> extends Result<List<T>> {

    @JsonIgnore
    @Override
    public List<T> getData() {
        return super.getData();
    }

    @JsonIgnore
    @Override
    public void setData(List<T> data) {
        super.setData(data);
    }
    /** 总记录数 */
    private long total;

    public long getTotal()
    {
        return total;
    }


    public void setTotal(long total)
    {
        this.total = total;
    }

    public List<T> getRows()
    {
        return getData();
    }

    public void setRows(List<T> rows)
    {
        setData(rows);
    }

    public static ResultRows toFail(String msg){
        var f=new ResultRows<>();
        f.setCode(500);
        f.setMsg(msg);
        return f;
    }

    public static  ResultRows bad(String msg){
        return toBad(msg);
    }
    public static ResultRows toBad(String msg){
        var f=new ResultRows<>();
        f.setCode(BAD);
        f.setMsg(msg);
        return f;
    }
    public static <T> ResultRows<T> byResule(Result<List<T>> re) {
        var f = new ResultRows<T>();
        f.setCode(re.getCode());
        f.setMsg(re.getMsg());
        f.setData(re.getData());
        if (re.getData() != null)
            f.setTotal(re.getData().size());
        return f;
    }
    public static ResultRows toEmpty(String msg){
        var f=new ResultRows<>();
        f.setCode(200);
        f.setMsg(msg);
        f.setTotal(0);
        return f;
    }
    public ResultRows(){}
    public ResultRows(long total, List<T> list){
        setTotal(total);
        setRows(list);
        setCode(200);
    }
}
